package util;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import org.primefaces.context.RequestContext;


public class AbstractMB {
	 private static final String KEEP_DIALOG_OPENED = "KEEP_DIALOG_OPENED";

	 public AbstractMB() {
	  super();
	 }

	 protected void displayErrorMessageToUser(String message) {
	  JSFMessageUtil messageUtil = new JSFMessageUtil();
	  messageUtil.sendErrorMessageToUser(message);
	 }

	 protected void displayInfoMessageToUser(String message) {
	  JSFMessageUtil messageUtil = new JSFMessageUtil();
	  messageUtil.sendInfoMessageToUser(message);
	 }

	 protected void closeDialog(){
	  getRequestContext().addCallbackParam(KEEP_DIALOG_OPENED, false);
	 }

	 protected RequestContext getRequestContext(){
		   return RequestContext.getCurrentInstance();
	 }
	 
	 protected void keepDialogOpen(){
	  getRequestContext().addCallbackParam(KEEP_DIALOG_OPENED, true);
	 } 

	 protected HttpServletRequest getHttpRequest(){
		   FacesContext context = FacesContext.getCurrentInstance();
		   return (HttpServletRequest) context.getExternalContext().getRequest();
	 }

}